<template>
	<!-- 授权记录 -->
	<view class="container">
		<view class="authorize-container" v-if="rightRecordList.length !== 0">
			<view class="item" v-for="(item,index) in rightRecordList" :key="index">
				<view class="left">
					<!-- <van-image width="110" height="110" fit="cover" @click="previewImg(recordImage[item.id].fileData)" :src="recordImage[item.id].fileData" /> -->
					<image v-if="recordImage[item.id]" :src="recordImage[item.id].fileData"></image>
				</view>
				<view class="content">
					<view class="top">
						<text class="username">{{item.name}}</text>
						<view class="type" v-if="item.residentType == 2">家人</view>
						<view class="type" v-if="item.residentType == 3">租户</view>
						<view class="type" v-if="item.residentType == 4">租户</view>
						<text class="time">{{item.guideTime}}</text>
					</view>
					<view class="phone">手机号码：{{item.mobile}}</view>
					<view class="card">身份证号码：{{item.personId}}</view>
				</view>
			</view>
		</view>
		<view v-else>
			<!-- 图片 -->
			<view class="img">
				<image src="../../static/icon/9.png" mode=""></image>
			</view>
			<!-- 暂无数据 -->
			<view class="tips">暂无记录</view>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				params: {
					projId: null,
					guideId: null,
					pagination: {
						current: 1,
						pageSize: 10000
					},
					sorter: {
						field: "id",
						order: 0
					}
				},
				rightRecordList: [],
				recordImage: {},
				imageList: []
			}
		},
		onLoad() {
			this.getRightList()
		},
		methods: {
			// 获取授权记录
			getRightList() {
				uni.showLoading()
				this.params.projId = uni.getStorageSync('projId')
				this.params.guideId = uni.getStorageSync('userInfo').id
				this.$http.post('/common/user/input/list',this.params).then(res => {
					console.log(res)
						uni.hideLoading()
					if(res.code === 10000){
						this.rightRecordList = res.data.list
					
						this.rightRecordList.forEach(item => {
							item.guideTime = this.$funcs.toLocalTime(item.guideTime)
							this.dowoLoadFile(item.picture,item.id)
						})
					}
				})
			},
			// 下载文件
			dowoLoadFile(picture,id) {
				this.$http.post('common/file/download',{id:picture}).then(res => {
					console.log(res)
					if(res.code === 10000){
						if(!this.recordImage[id]){
							this.recordImage[id] = {}
						}
						this.imageList.push(res.data.fileData)
						this.recordImage[id].fileData = res.data.fileData
						console.log(this.recordImage)
					}
				})
			},
			// 预览图片
			previewImg(url) {
				let img = []
				img.push(url)
				uni.previewImage({
				  urls: img,
				  longPressActions: {
				    itemList: ["发送给朋友", "保存图片", "收藏"],
				    success: function (data) {
				      console.log(
				        "选中了第" +
				          (data.tapIndex + 1) +
				          "个按钮,第" +
				          (data.index + 1) +
				          "张图片"
				      )
				    },
				    fail: function (err) {
				      console.log(err.errMsg);
				    }
				  }
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
	.authorize-container {
		padding: 20rpx;
		background:rgba(245,245,245,1);
		height:1207rpx;
		.item {
			width: 710rpx;
			height: 200rpx;
			margin-bottom: 21rpx;
			display: flex;
			box-shadow: 0px 2rpx 8rpx 0px rgba(204, 204, 204, 0.5);
			.left {
				width: 200rpx;
				height: 200rpx;
				// flex: 1;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.content {
				flex: 1;
				padding-top: 24rpx;
				padding-left: 12rpx;
				height: 100%;
				// height: 200rpx;
				color: #656565;
				font-size: 28rpx;
				background-color: #fff;
				.phone {
					margin-top: 20rpx;
				}
				.card {
					margin-top: 20rpx;
				}
				.top {
					height: 40rpx;
					display: flex;
					align-items: center;
					position: relative;
					.type {
						// margin-top: 2rpx;
						border: 1rpx solid #FF8989;
						font-size: 20rpx;
						color: #FF8A8A;
						width: 60rpx;
						height: 30rpx;
						text-align: center;
						line-height: 30rpx;
					}
					.username {
						// width: 120rpx;
						color:#000033;
						margin-right: 21rpx;
					}
					.time {
						position: absolute;
						right: 23rpx;
						top: 6rpx;
						font-size: 24rpx;
					}
				}
			}
		}
	}
	.img {
		width: 258rpx;
		height: 246rpx;
		margin: 67rpx 245rpx 34rpx 247rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
	.tips {
		margin: 0 315rpx 0 315rpx;
		width: 120rpx;
		height: 27rpx;
		font-size: 28rpx;
		font-family: Noto Sans S Chinese;
		font-weight: 500;
		color: rgba(194, 194, 194, 1);
	}
	}
</style>
